package com.xinya.taobaosale.ui.adapter;

import android.util.Log;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.xinya.taobaosale.model.domain.HomePagerDiscoveryBean;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

/**
 * @ClassName: HomePagerBannerAdapter$
 * @Description: java类作用描述
 * @Author: xinya
 * @CreateDate: 2021/2/5$ 11:18$
 * @UpdateRemark: 更新内容
 * @Version: 1.0
 */
public class HomePagerBannerAdapter extends BannerAdapter<HomePagerDiscoveryBean, HomePagerBannerAdapter.BannerViewHolder> {

    private static final String TAG = "HomePagerBannerAdapter";

    public HomePagerBannerAdapter(List<HomePagerDiscoveryBean> datas) {
        super(datas);
    }

    @Override
    public BannerViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        ImageView imageView = new ImageView(parent.getContext());
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return new BannerViewHolder(imageView);
    }

    @Override
    public void onBindView(BannerViewHolder holder, HomePagerDiscoveryBean data, int position, int size) {
        ViewGroup.LayoutParams params = holder.imageView.getLayoutParams();
        int length = Math.min(params.width, params.height);
//        String url = "https:" + data.getPict_url();
        String url = "https:" + data.getPict_url() + "_" + 300 + "x" + 300 +".jpg";
        Glide.with(holder.imageView.getContext()).load(url).into(holder.imageView);
    }


    static class BannerViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;

        public BannerViewHolder(@NonNull ImageView view) {
            super(view);
            this.imageView = view;
        }
    }
}
